﻿//* Copyright(C) 2005-2012, all rights reserved.
//*
//* The following code is copyrighted and contains proprietary information
/* and trade secrets of Foxit Software Inc.      
**************************************************************************
*/

/**
Navigation MainFrm鼠标事件接口类
*/


define(function (require, exports, module) {
    var IReader_MainFrmEventHandler = FXREADER.Event.IReader_MainFrmEventHandler;
    var Interface = FXREADER.Interface;


    var CNavigationPanel_MainFrmEventHandler = function (pNavigationPanel) {
        this.m_pNavigationPanel = pNavigationPanel;
        this.m_bMouseDown = false,
        this.m_bOldPosX = 0;
        this.m_nMinLeftPanelWidth = 170;
        var _self = this;
        $("#" + _self.m_pNavigationPanel.GetSplitterDivID()).mousedown(function (event) {
            FXREADER.Common.PreventDefaults(event, true);
            _self.m_bMouseDown = true;
            _self.m_bOldPosX = event.pageX;

            var panelWidth = _self.m_pNavigationPanel.GetPanelWidth();
           var splitterWidth = $(this).width();
           $("#" + _self.m_pNavigationPanel.GetMoveSplitterDivID()).css({ left: panelWidth - splitterWidth });

            return true;
        });


        this.OnMouseUp = function (event) {
            if (this.m_bMouseDown) {
                var panelWidth = this.m_pNavigationPanel.GetPanelWidth();
                var newWidth = panelWidth + event.pageX - this.m_bOldPosX;
                var jqTreePanel = $("#" + this.m_pNavigationPanel.GetTreePanelDivID());
                var nOldTreePanelWidth = jqTreePanel.width();
                var nNewTreePanelWidth = nOldTreePanelWidth + event.pageX - this.m_bOldPosX;
                if (newWidth < this.m_nMinLeftPanelWidth) {
                    this.m_bMouseDown = false;
                    this.m_pNavigationPanel.DisablePanel(true, false, true);
                    $("#" + this.m_pNavigationPanel.GetMoveSplitterDivID()).css({ left: -10000 });
                    jqTreePanel.width(nNewTreePanelWidth);
                    this.m_pNavigationPanel.OnSize();
                    return true;
                }

               // var jqTreePanel = $("#" + this.m_pNavigationPanel.GetTreePanelDivID());
                //var nOldTreePanelWidth = jqTreePanel.width();
                //var nNewTreePanelWidth = nOldTreePanelWidth + event.pageX - this.m_bOldPosX;
                $("#" + this.m_pNavigationPanel.GetMoveSplitterDivID()).css({ left: -10000 });
                jqTreePanel.width(nNewTreePanelWidth);

                this.m_pNavigationPanel.OnSize();
                this.m_bMouseDown = false;
                return true;
            }
            this.m_bMouseDown = false;
            return false;
        }

    };

    CNavigationPanel_MainFrmEventHandler.prototype =
    {
        GetType: function () { return "Navigation Panel"; },
        OnLButtonDown: function (event) { return false; },
        OnLButtonUp: function (event) {
            return this.OnMouseUp(event);
        },
        OnMouseMove: function (event) {
            if (!this.m_bMouseDown) return false;
            FXREADER.Common.PreventDefaults(event, true);
            var panelWidth = this.m_pNavigationPanel.GetPanelWidth();
            var tabPanelWidth = $("#" + this.m_pNavigationPanel.GetTabPanelDivID()).width();
            var splitterWidth = $("#" + this.m_pNavigationPanel.GetSplitterDivID()).width();
            var newWidth = panelWidth + event.pageX - this.m_bOldPosX;
            if (newWidth < tabPanelWidth + splitterWidth) {
                return true;
            }
            $("#" + this.m_pNavigationPanel.GetMoveSplitterDivID()).css({ left: newWidth - splitterWidth });
            return true;
        },
        OnMouseOut: function (event) { return false; },
        OnMouseLeave: function (event) { return this.OnMouseUp(event); },
        OnSize: function () {
            this.m_pNavigationPanel.OnMainFrmSize();
        }
    };


    FXREADER.Event.CNavigationPanel_MainFrmEventHandler = CNavigationPanel_MainFrmEventHandler;
    return FXREADER.Event.CNavigationPanel_MainFrmEventHandler;
});